<?php
/**
 * Projects Model
 *
 * PHP Version 5
 *
 * @package    Ecga
 * @subpackage Models
 * @author     FarmerLi <lixu_01@126.com>
 * @copyright  2010 Xingchangxinda Inc.
 * @version    SVN:$Id: projects.php 3051 2011-01-11 13:06:18Z sunbo $
 */

namespace Project\Apps\Ecga\Models;

use \Project\Models\Abstraction\Ecga\Projects as bizProjects;


/**
 * masters Model
 *
 * PHP version 5
 *
 * @package   Ecga
 * @author    FarmerLi <lixu_01@126.com>
 * @copyright 2010 Xingchangxinda Inc.
 * @version   Release: 0.1
 */
class Projects extends bizProjects
{
	/**
     * 获取项目列表
     *
     * @author Farmer.Li <lixu_01@126.com>
     *
     * @return void
     */
    public function getProjects()
    {
        static $return = null;
        
        if (null === $return) {
            $select = $this->select(
                'id',
                'projectName',
                'batchConfig'
            );
            $return = $select->fetch();
            $return = iterator_to_array($return);
            foreach ($return as $key => $value) {
            	$batch = explode(',', $value['batchConfig']);
            	$return[$key]['batchConfig'] = array();
            	foreach ($batch as $t) {
            		$return[$key]['batchConfig'][$t] = $t;
            	}
            }
        }

        return $return;
    }
    
    /**
     * 获取所有项目 options格式
     * 
     * @return array
     */
    public function getOptions()
    {
    	$projects = $this->getProjects();
    	$result = array();
    	foreach ($projects as $value) {
    		$result[$value['id']] = $value['projectName'];
    	}
    	return $result;
    }
    
    /**
     * 取分页query
     *
     * @param array $filterArray 过滤器参数  
     * 
     * @return query $query
     * @author sunfengming
     */
    public static function getPageQuery($filterArray = array())
    {
    	$model = model('Projects');
        $filter = $model->filter();
        foreach ($filterArray as $key => $value) {
            if ('id' == $key) {
                $filter->where($key, 'IN', $value);
            }
        }

    	return $model->query($filter)->fields('id', 'projectName', 'batchConfig');
    }
}